package com.smh.a03exerciseDemo1;

import java.util.Scanner;

public class Test1 {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        GirlFriend girlFriend = new GirlFriend();
        String name;
        int age;
//        while (true){
//            name=scanner.nextLine();
//            try {
//                if (name.length()<3||name.length()>10){
//                    throw new RuntimeException("姓名异常");
//                }
//            } catch (RuntimeException e) {
//                continue;
//            }
//            break;
//        }
//        while (true){
//            try {
//                ageStr=scanner.nextLine();
//                age = Integer.parseInt(ageStr);
//                if (age<18||age>40){
//                    throw new RuntimeException("年龄异常");
//                }
//            } catch (ClassCastException e){
//                e.printStackTrace();
//                continue;
//            }   catch (RuntimeException e) {
//                continue;
//            }
//            break;
//        }
        while (true) {
            try {
                System.out.println("姓名");
                name = scanner.nextLine();
                girlFriend.setName(name);
                System.out.println("年龄");
                String ageStr = scanner.nextLine();
                age = Integer.parseInt(ageStr);
                girlFriend.setAge(age);
                break;
            } catch (NumberFormatException e) {
                System.out.println("年龄格式异常");
            } catch (RuntimeException e) {
                System.out.println("姓名和年龄范围有误");
            }
        }
        System.out.println(girlFriend);


    }
}
